﻿namespace TvUtil.Console
{
	using System;
	using System.Collections.Generic;
	using System.Text;

	class Program
	{
		static void Main(string[] args)
		{
			DateTime dateTime = DateTime.Now;
			if (args != null && args.Length > 0 && args[0] != null)
			{
				try
				{
					dateTime = DateTime.Parse(args[0]);
				}
				catch (Exception ex)
				{
					Console.WriteLine(ex.Message);
					Console.WriteLine("Example: ./tvutil 20.06.2008");
					return;
				}
			}
			ProgramStation[] stations = ProgramStation.Create(dateTime);
			char channel = 'a';
			for (int i =0; i < stations.Length; ++i)
			{
				ProgramStation station = stations[i];
				Console.SetCursorPosition(i*20,0);
				Console.Write(station.Name);
				int num = 0;
				for (int j = 0; j < station.Shows.Count; ++ j )
				{
					Console.SetCursorPosition(i * 20, 1 + j);
					string text = string.Format("{4}{3}){0}:{1} {2}", station.Shows[j].Time.Hours, 
						station.Shows[j].Time.Minutes,
						station.Shows[j].Name, num, channel);
					int len = text.Length;
					if (len > 20)
					{
						text = text.Substring(0, 17) + "..";
					}
					Console.Write(text);
					++num;
				}
				++channel;
			}
			Console.ReadLine();
		}
	}
}
